var assert = require('assert');
var should = require('should');
var util = require('util');
var _ = require('lodash');
var bagModel = require('../../app/models/bagModel');
var config = require('../config');
var mongoConnector = require('../../app/libs/mongodb/mongoConnector');
var Bag = mongoConnector().model('Bag');

suite('测试bagModel', function () {
    var bag_model;
    setup(function (done) {
        Bag.remove({
            role_id: config.role_id
        }, function (err) {
            if (err) {
                return handleError(err);
            }

            bagModel.getByRoleId(config.role_id, function (err, model) {
                assert.equal(err == null, true);
                bag_model = model;
                done();
            });
        });
    });

    suite('subProperty', function () {
        test('添加道具', function () {
            bag_model.subProperty(100);
        });
    });

    var consume_list = {};
    suite('consume_list', function () {
        test('获取消耗品列表', function () {
            bag_model.getConsumeList();
        });
    });

    suite('getConsume', function () {
        test('获取消耗品', function () {
            bag_model.getConsume(3000101);
        });
    });

    suite('addConsume', function () {
        test('添加消耗品', function () {
            bag_model.addConsume(5000201).should.equal(true);
        });
    });

    suite('removeConsume', function () {
        test('删除消耗品失败', function () {
            bag_model.removeConsume(5000201).should.equal(false);
        });
    });

    suite('addEquip', function () {
        test('添加装备', function () {
            bag_model.addEquip(config.equip_id);
            var equip = bag_model.equip_list[0];
            equip.getId();
            equip.getLv();
            equip.upgrade();
        });
    });

    suite('addProperty', function () {
        test('添加材料', function () {
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            var property = bag_model.property_list[0];
            property.getId();
            property.addStackNum();
            property.getStackNum();
            property.subStackNum();
        });

        test('验证添加道具是否可以叠加', function (done) {
            bag_model.property_list = [];
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            var property = bag_model.property_list[0];
            bag_model.property_list.length.should.equal(1);
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            bag_model.property_list.length.should.equal(1);
            bag_model.save(done);
        });

        test('验证添加道具是否可以叠加', function (done) {
            bag_model.property_list = [];
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            var property = bag_model.property_list[0];
            bag_model.property_list.length.should.equal(1);
            bag_model.addProperty(config.property_id, 1).should.equal(true);
            bag_model.property_list.length.should.equal(1);
            bag_model.save(done);
        });

        test('验证添加道具不存在', function () {
            bag_model.addProperty(1, 1).should.equal(false);
        });
    });

    suite('removeProperty', function () {
        test('删除材料失败', function () {
            bag_model.removeProperty(1).should.equal(false);
        });
    });

    suite('removeEquip', function () {
        test('删除装备', function () {
            bag_model.removeEquip(1).should.equal(false);
        });
    });

    suite('addEquip', function () {
        test('获取装备', function (done) {
            assert.equal(bag_model.addEquip(1063301) !== null, true);
            bag_model.save(function (err) {
                assert.equal(null, err);
                done();
            });
        });
    });

    suite('getEquip', function () {
        test('获取装备', function () {
            bag_model.getEquip(1000);
        });
    });

    suite('equip', function () {
        test('穿上装备', function () {
            bag_model.equip(1);
        });
    });

    suite('getPropertyList', function () {
        test('获取道具列表', function () {
            bag_model.getPropertyList();
        });
    });

    suite('getEquipList', function () {
        test('获取装备列表', function () {
            bag_model.getEquipList();
        });
    });

    suite('getWearEquipList', function () {
        test('获取穿上的装备列表', function () {
            bag_model.getWearEquipList();
        });
    });

    // suite('resetAdditiveAttr', function () {
    //     test('重置附加属性', function () {
    //         bag_model.addEquip(1063301);
    //         var equip_list = bag_model.getEquipList();
    //         var equip = equip_list[bag_model.equip_list.length - 1];
    //         var attr = equip.additive_attr_list[0];
    //         equip.resetAdditiveAttr(attr).should.equal(true);
    //     });
    // });

    suite('addEquipWithAttrAndHole', function () {
        test('添加装备', function () {
            bag_model.addEquipWithAttrAndHole(1, 1, 1, 1);
        });
    });
});
